<template>
	<view class="uni-popup-share">
		<view class="uni-share-img flex">
			<image :src="shareSrc"></image>
		</view>
		<view class="uni-share-content">
			<view class="uni-share-content-box">
				<view class="uni-share-content-item" v-for="(item,index) in bottomData" :key="index" @click.stop="select(item,index)">
					<image class="uni-share-image" :src="item.icon" mode="aspectFill"></image>
					<text class="uni-share-text">{{item.text}}</text>
				</view>

			</view>
		</view>
		<view class="uni-share-button-box">
			<button class="uni-share-button" @click="close">取消</button>
		</view>
	</view>
</template>

<script>
	import permision from "@/js_sdk/wa-permission/permission.js"
	export default {
		name: 'UniPopupShare',
		props: {

		},
		inject: ['popup'],
		data() {
			return {
				bottomData: [{
						text: '保存图片',
						icon: '../../static/index/download.png'
					},
					{
						text: '微信好友',
						icon: '../../static/index/wechat1.png'
					},
					{
						text: '朋友圈',
						icon: '../../static/index/friend.png'
					},
					{
						text: 'QQ好友',
						icon: '../../static/index/qqfriends.png'
					},
					{
						text: '微博',
						icon: '../../static/index/weibo.png'
					}
				],
				shareSrc: '../../static/index/share-shop.png'
			}
		},
		created() {},
		methods: {
			async requestAndroidPermission(permisionID) {
				var result = await permision.requestAndroidPermission(permisionID)
				var strStatus
				if (result == 1) {
					strStatus = "已获得授权"
					uni.saveImageToPhotosAlbum({
						filePath: this.shareSrc,
						success: function() {
							uni.showToast({
								title: '成功保存到相册',
								icon: 'none',
								duration: 1000
							})
						},
						fail: function() {
							uni.showToast({
								title: '保存到相册失败',
								icon: 'none',
								duration: 1000
							})
						}
					});
				} else if (result == 0) {
					strStatus = "未获得授权"
					permision.gotoAppPermissionSetting()
				} else {
					strStatus = "被永久拒绝权限"
					permision.gotoAppPermissionSetting()
				}
				// uni.showModal({
				// 	content: permisionID + strStatus,
				// 	showCancel: false
				// });
			},
			/**
			 * 选择内容
			 */
			select(item, index) {
				var that = this
				console.log(item, index)
				if (index == 0) { //保存图片
					if (plus.os.name == 'iOS') {
						console.log(111)
						permision.judgeIosPermission("photoLibrary")
					}
					this.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
					this.requestAndroidPermission('android.permission.WRITE_EXTERNAL_STORAGE')
				} else {
					var provider = '', scene = '', title = '分享',
						summary = '欢迎加入亚林彩'
					if (index == 1 || index == 2) {
						provider = "weixin"
						if (index == 1) {
							scene = "WXSceneSession" //微信好友
						} else {
							scene = "WXSenceTimeline" //朋友圈
						}
					}
					if (index == 3) {//qq好友
						provider = "qq"
					} 
					if(index == 4){//微博
						provider = "sinaweibo"
					}
					uni.share({
						provider: provider,
						scene: scene,
						type: 2,
						title: title,
						summary: summary,
						imageUrl: this.shareSrc,
						success: function(res) {
							console.log(res);
						},
						fail: function(err) {
							console.log(err);
						}
					});
				}
				// this.$emit('select', {
				// 	item,
				// 	index
				// }, () => {
				// 	wx.showTabBar();
				// 	this.popup.close()
				// })
				setTimeout(function() {
					that.close()
				}, 1000)
			},
			/**
			 * 关闭窗口
			 */
			close() {
				wx.showTabBar();
				this.popup.close()
			}
		}
	}
</script>
<style lang="scss" scoped>
	.uni-popup-share {
		// margin-bottom: 30rpx;
	}

	// /deep/.uni-popup__mask {
	// 	background: rgba(0, 0, 0, 0) !important;
	// }

	// .uni-share-title {
	// 	/* #ifndef APP-NVUE */
	// 	display: flex;
	// 	/* #endif */
	// 	flex-direction: row;
	// 	align-items: center;
	// 	justify-content: center;
	// 	height: 40px;
	// }
	// .uni-share-title-text {
	// 	font-size: 14px;
	// 	color: #666;
	// }
	.uni-share-content {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		padding-top: 30px;
		background-color: #fff;
	}

	.uni-share-content-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		flex-wrap: wrap;
		width: 360px;
	}

	.uni-share-content-item {
		width: 20%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		padding: 10px 0;
		align-items: center;
	}

	.uni-share-content-item:active {
		background-color: #f5f5f5;
	}

	.uni-share-image {
		width: 80rpx;
		height: 80rpx;
	}

	.uni-share-text {
		margin-top: 10px;
		font-size: 14px;
		color: #3B4144;
	}

	.uni-share-button-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		padding: 10px 15px;
		background-color: #fff;
	}

	.uni-share-button {
		flex: 1;
		border-radius: 50px;
		color: #666;
		font-size: 16px;
	}

	.uni-share-button::after {
		border-radius: 50px;
	}

	.uni-share-img {
		align-items: flex-start;
		justify-content: center;
		position: absolute;
		bottom: 160px;
		left: 50%;
		transform: translateX(-50%);

		image {
			width: 564rpx;
			height: 948rpx;
		}
	}
</style>
